﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AuthConfig.cs" company="ecblog.codeplex.com">
//   emrecoskun.net - ibrahimatay.com
// </copyright>
// <summary>
//   The auth config.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace EcBlog
{
    using EcBlog.Composition;
    using EcBlog.Data;
    using EcBlog.Models;

    using Microsoft.Web.WebPages.OAuth;

    using WebMatrix.WebData;

    /// <summary>
    ///   The auth config.
    /// </summary>
    public static class AuthConfig
    { 
        /// <summary>
        ///   The register auth.
        /// </summary>
        public static void RegisterAuth()
        {
            var setting = ((IEcUnitOfWork)CompositionDependencyResolver.StaticFactory.GetService(typeof(IEcUnitOfWork))).SiteSettingRepository;
            
            var microsoftAuthClientId = setting[SiteSettingKey.MicrosoftAuthClientId];
            var microsoftAuthSecret = setting[SiteSettingKey.MicrosftAuthSecret];

            if (!string.IsNullOrEmpty(microsoftAuthSecret) && !string.IsNullOrEmpty(microsoftAuthClientId))
            {
                OAuthWebSecurity.RegisterMicrosoftClient(microsoftAuthClientId, microsoftAuthSecret);
            }

            var twitterAuthClientId = setting[SiteSettingKey.TwitterConsumerKey];
            var twitterAuthSecret = setting[SiteSettingKey.TwitterConsumerSecret];

            if (!string.IsNullOrEmpty(twitterAuthClientId) && !string.IsNullOrEmpty(twitterAuthSecret))
            {
                OAuthWebSecurity.RegisterTwitterClient(twitterAuthClientId, twitterAuthSecret);
            }

            var facebookAuthClientId = setting[SiteSettingKey.FacebookAppId];
            var facebookAuthSecret = setting[SiteSettingKey.FacebookAppSecret];

            if (!string.IsNullOrEmpty(facebookAuthClientId) && !string.IsNullOrEmpty(facebookAuthSecret))
            {
                OAuthWebSecurity.RegisterFacebookClient(facebookAuthClientId, facebookAuthSecret);
            } 

            OAuthWebSecurity.RegisterGoogleClient();

            // WebMail.SmtpServer = "mailserver.example.com";
            // WebMail.EnableSsl = true;
            // WebMail.UserName = "username@example.com";
            // WebMail.Password = "your-password";
            // WebMail.From = "your-name-here@example.com";
        } 
    }
}